#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <unistd.h>
#include <string.h>
#include <math.h>

#define tupleNum	5000*500 * 8 

int main(int argc, char ** argv){
	int *scanCol, *whereCol ;
	int i,j;
	int key,value;

	if(argc != 5){
		printf("./scanBinaryGen colSize scanColNum whereColNum attrSize\n");
		exit(-1);
	}

	int colSize = atoi(argv[1]);
	int scanColNum = atoi(argv[2]);
	int whereColNum = atoi(argv[3]);
	int attrSize = atoi(argv[4]);

	scanCol = (int *)malloc(sizeof(int) * scanColNum);
	whereCol = (int *)malloc(sizeof(int) * whereColNum);

	if(!scanCol || !whereCol ){
		printf("failed to allocate memory!");
		exit(-1);
	}

	for(i=0;i<scanColNum;i++){
		char buf[32]= {0};
		sprintf(buf, "scanTable%d",i);
		scanCol[i] = open(buf,O_WRONLY|O_CREAT);
	}

	for(i=0;i<whereColNum;i++){
		char buf[32]= {0};
		sprintf(buf, "whereTable%d",i);
		whereCol[i] = open(buf,O_WRONLY|O_CREAT);
	}

// here we don't care the actual value in the scan col

	char buf[128] = {0};

	for(i=0;i<sizeof(buf);i++){
		buf[i] = 'a';
	}

	for(i=0;i<tupleNum * colSize;i++){
		for(j=0;j<scanColNum;j++){
			write(scanCol[j],buf,attrSize);
		}
	}

// the value of where col will be between 0 and 100(100 not included)

	for(i=0; i<tupleNum * colSize; i++){
		value = i % 100;
		for(j=0;j<whereColNum;j++){
			write(whereCol[j],&value,sizeof(int));
		}
	}

	for(i=0;i<scanColNum;i++){
		close(scanCol[i]);
	}
	for(i=0;i<whereColNum;i++){
		close(whereCol[i]);
	}

	return 0;
}
